home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
stazsoftware.com
/
www.stazsoftware.com.tar
/
www.stazsoftware.com
/
futurebasic
/
sample-code
/
AppleScriptFB.sit
/
USR AppleScriptRun
next >
Wrap
Text File
|
2004-02-10
|
5KB
|
209 lines
/*
This example tests a few AppleScript scripts.
Alain ( 9/5/02 }
*/
'~'6
#if def _usingLiteRuntime
Print "This example is not designed to work in the Console"
#else
include "Subs AppleScript.Incl"
local fn doAppleScript( whichOne as int )
'~'9
dim as str255 message
dim as handle resultH
dim as OSErr err
route _toAppleScript
select whichOne
case 1
print "tell application ""Finder"""
print " the name of the startup disk"
print "end tell"
case 2
print "tell application ""Finder"""
print " the name of every disk"
print "end tell"
case 3
print "tell application ""Finder"""
print " set nbFolders to the count of folders of the startup disk"
print " say ""[[emph +]]I [[emph +]]can't believe it!"""
print " say ""You have "" & nbFolders & "" folders on your hard drive"""
print "end tell"
case 4
print "tell application ""Finder"""
print " the name of every folder of the startup disk"
print "end tell"
case 5
print "tell application ""Finder"""
print " the last folder of the startup disk"
print "end tell"
case 6
print "tell application ""Finder"""
print " the name of every folder of the startup disk whose label index is not 0"
print "end tell"
case 7
print "tell application ""Finder"" to count every file of startup disk"
case 8
print "tell application ""Finder"""
print " if folder ""Apple Extras"" of startup disk exists then"
print " count files in folder ""Apple Extras"" of startup disk"
print " else"
print " return ""no Apple Extras folder found"""
print " end if"
print "end tell"
case 9
print "return path to me as string"
case 11
print "tell application ""Finder"""
print " activate"
print " display dialog ""What's your name?"""
print "end tell"
case 12
print "set theCount to number of files in front window of application ""Finder"""
print "if theCount > 50 then"
print " display dialog ""You have exceeded your file limit."""
print "else"
print " display dialog ""You're a good boy!"""
print "end if"
case 13
print "display dialog ""Ready to test your patience?"""
print "set myDate to current date"
long if system(_sysVers) > 810
print "delay 4"
xelse
print "╟event sysodela╚ 4"
end if
print "display dialog ""4 second delay on "" & (date string of myDate) & ""."""
case 15
print "set myself to path to me as alias"
print "tell application ""Finder"""
print " try
print " make new alias file at apple menu items folder to myself"
print " on error"
print " error ""Une erreur est survenue lors de la crÄation de l╒alias."""
print " end try"
print "end tell"
case 16
print "tell application ""Finder"""
print " set appPath to """""
print " try"
print " set appPath to application file id ""RSED"" as string"
print " end try"
print "end tell"
print "if appPath ¡ """" then"
print " with timeout of 5 seconds"
print " launch application appPath"
print " end timeout"
print "else"
print " return ""not found"""
print "end if"
case 17
print "tell application ""AppleWorks"""
print " make new document at beginning with properties {name:""New Report""}"
print "end tell"
case 18
print "on factorial(x)"
print " if x > 0 then"
print " return x * (factorial(x - 1))"
print " else"
print " return 1"
print " end if"
print "end factorial"
print "return factorial(10)"
case 20
print "the current date as string"
end select
route _toScreen
err = usr AppleScriptRun( message )
// result must be extracted even when an error has occurred.
resultH = usr AppleScriptGetResult
long if resultH
call TESetText([resultH],fn GetHandleSize( resultH ), tehandle( 1 ))
call DisposeHandle( resultH )
cls
print "Choose a script under the Script menu"
xelse
edit$( 1 ) = message
end if
end fn
local fn doMenu
'~'9
dim as short menuID, itemID
menuID = menu( _menuID )
itemID = menu( _itemID )
select menuID
case 1 : end
case 3 : fn doAppleScript( itemID )
end select
menu
end fn
'~Main program
menu 1,0,_enable,"File"
menu 1,1,_enable,"Quit/Q"
edit menu 2
menu 3,0,_enable,"Script"
menu 3,1,_enable,"Name of Startup Disk"
menu 3,2,_enable,"List of Mounted Disks"
menu 3,3,_enable,"Number of Folders at Root Level"
menu 3,4,_enable,"List of Folders at Root Level"
menu 3,5,_enable,"Last Folder of Root Level"
menu 3,6,_enable,"Labelled Folders at Root Level"
menu 3,7,_enable,"Number of Files at Root Level"
menu 3,8,_enable,"Number of Files in Extras Folder"
menu 3,9,_enable,"My file access path"
menu 3,11,_enable,"Display Dialog"
menu 3,12,_enable,"Conditional Dialog"
menu 3,13,_enable,"Delay"
menu 3,15,_enable,"Create an Alias in Apple Menu"
menu 3,16,_enable,"Launch ResEdit"
menu 3,17,_enable,"New AppleWorks Document"
menu 3,18,_enable,"Recursive Function Called"
menu 3,20,_enable,"Current date"
window 1
print "Choose a script under the Script menu"
_fldMargin = 32
edit field 1,"",(_fldMargin,_fldMargin)-(Window(_width)-_fldMargin,Window(_height)-_fldMargin)
on menu fn doMenu
do
handleevents
until _nil
#endif